package com.leetcode.LC_MED;

import java.util.List;

public class LC120 {
    public int minimumTotal(List<List<Integer>> triangle) {

        if (triangle == null || triangle.size() == 0) {
            return 0;
        }
        int a = triangle.size();
        int b = triangle.get(a - 1).size();
        int[][] ints = new int[a][b];
        int tmp=0;
        for (List<Integer> list : triangle) {
            for (int i = 0; i < list.size(); i++) {
                ints[tmp][i]=list.get(i);
            }
            tmp++;
        }

        for (int i = a - 1; i >= 1; i--) {
            for (int j = b - 1; j >= 1; j--) {
                ints[i - 1][j - 1] = Math.min(ints[i - 1][j - 1] + ints[i][j], ints[i - 1][j - 1] + ints[i][j - 1]);
            }
        }
        return ints[0][0];
    }
}
